import Vue from 'vue'
import VueRouter from 'vue-router'
import one from './module/Li-J/ShopList.js'
import mrouter from './module/mzt.js'
import haha from "./module/jie.js"
import hroute from "./module/hjn.js"
import hp from './module/hhp.js'
import gm from './module/gmm.js'
import jie from './module/jie.js'
import lzrouter from "./module/lizhi.js"

Vue.use(VueRouter)

const routes = [

  {
    path: '/home',
    name: 'home',
    component: () => import('../views/HomeView.vue'),
    children: [//配置二级路由规则



      ...gm,
      ...hroute,
      // 此处添加你的路由模块
      ...mrouter,
      ...hp,
      ...one,
      ...jie,
      //李智的路由页面
      ...lzrouter,
    ]
  },
  {
    path: '/denglu',
    name: 'denglu',
    component: () => import('../views/DengLu.vue')
  },

  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  ...haha,

  //重定向
  {
    path: '/',
    redirect: "/denglu"

  },

  //404
  {
    path: '*',
    name: 'nov',
    component: () => import('../views/NoView.vue')
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
    let token=localStorage.getItem("token")
    if(to.path=="/denglu"){
     next()
    }else if(token){
     next()
    }else{
     next("/denglu")
    }
   })


export default router

